from datetime import datetime

from fastapi import Request
from sqlalchemy.ext.asyncio import AsyncSession

from module_basics.entity.vo.log_vo import ContrastLogModel
from module_basics.service.log_service import ContrastLogService


class ComparisonLogUtil:

    @classmethod
    def insert_contrast_log(cls, request: Request, query_db: AsyncSession, contrast_log: ContrastLogModel):
        contrast_log.host_ip = request.headers.get('X-Forwarded-For')
        contrast_log.operation_time = datetime.now()
        contrast_log.operating_location = '内网IP'
        operation_log_result = ContrastLogService.add_contrast_log_services(query_db, contrast_log)
        return operation_log_result
